/*
 * CreateCorridorAction.java
 * 
 * Created by demory on Oct 16, 2009, 9:04:49 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.cart.actions;

import org.fpdev.apps.cart.Cartographer;
import org.fpdev.apps.cart.Editor;
import org.fpdev.apps.cart.network.AnchorPoint;
import org.fpdev.apps.cart.network.Corridor;

/**
 *
 * @author demory
 */
public class CreateCorridorAction extends EditorBasedAction {

  private Corridor corridor_;
  private AnchorPoint from_, to_;

  public CreateCorridorAction(Editor ed, AnchorPoint from, AnchorPoint to) {
    super(ed);
    from_ = from;
    to_ = to;
  }

  public boolean doAction(Cartographer cart) {
    corridor_ = new Corridor(ed_.getDocument().getNetwork().newCorridorID(), from_, to_, true);
    ed_.getDocument().getNetwork().addCorridor(corridor_);
    return true;
  }

  public boolean undoAction(Cartographer cart) {
    if(corridor_ == null) return false;

    ed_.getDocument().getNetwork().deleteCorridor(corridor_);
    return true;
  }

  public String getName() {
    return "Create Corridor";
  }


}
